package com.zmn.oms.common.dto;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.constant.StatusConsts;

/**
 * 类描述：执行结果对象
 *
 * @author liuying
 * @date 2018/11/23 14:53
 */
public class ResultDTO<T> {

    /**
     * 数值结果,如200,404
     */
    private int status;
    /**
     * Bool结果,如true,false
     */
    private boolean statusBool;
    /**
     * 相关ID
     */
    private T data;
    /**
     * 文本信息
     */
    private String message;

    public ResultDTO() {
    }

    public ResultDTO(int status, boolean statusBool, String message) {
        this.status = status;
        this.statusBool = statusBool;
        this.message = message;
    }

    public ResultDTO(int status, boolean statusBool, String message, T data) {
        this.status = status;
        this.statusBool = statusBool;
        this.message = message;
        this.data = data;
    }

    public ResultDTO(boolean statusBool) {
        this.statusBool = statusBool;
        if (statusBool) {
            this.status = StatusConsts.STATUS_SUCCESS;
        } else {
            this.status = StatusConsts.STATUS_ERROR;
        }
    }

    public ResultDTO(boolean statusBool, String message) {
        this.statusBool = statusBool;
        this.message = message;
        if (statusBool) {
            this.status = StatusConsts.STATUS_SUCCESS;
        } else {
            this.status = StatusConsts.STATUS_ERROR;
        }
    }

    public ResultDTO(boolean statusBool, String message, T data) {
        this.statusBool = statusBool;
        if (statusBool) {
            this.status = StatusConsts.STATUS_SUCCESS;
        } else {
            this.status = StatusConsts.STATUS_ERROR;
        }
        this.message = message;
        this.data = data;
    }

    public ResultDTO(boolean statusBool, T data) {
        this.statusBool = statusBool;
        if (statusBool) {
            this.status = StatusConsts.STATUS_SUCCESS;
        } else {
            this.status = StatusConsts.STATUS_ERROR;
        }
        this.data = data;
    }

    public static ResultDTO success() {
        return new ResultDTO(true, GlobalConsts.SUCCESS_MSG);
    }

    public static ResultDTO success(int status, String message) {
        return new ResultDTO(status, true, message);
    }

    public static ResultDTO success(Object data) {
        return new ResultDTO<>(true, data);
    }

    public static ResultDTO success(Object data, String message) {
        ResultDTO resultDTO = new ResultDTO<>(true, data);
        resultDTO.setMessage(message);
        return resultDTO;
    }

    public static ResultDTO fail(String message) {
        return new ResultDTO(StatusConsts.STATUS_ERROR, false, message);
    }

    public static ResultDTO fail(int status, String message) {
        return new ResultDTO(status, false, message);
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public boolean isStatusBool() {
        return statusBool;
    }

    public void setStatusBool(boolean statusBool) {
        this.statusBool = statusBool;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
